<?
/***
    * @package ajax
    * @author A Kulikov <a.kulikov@gmail.com>
    * @version n/a
    ***/
    class ajaxGetCoordinates extends ajaxAction{

        public function process(){              
            global $GLOBALS;
        
            foreach($_REQUEST as $key => $val){
                $_REQUEST[$key] = urlencode($this->utf8_urldecode($val));
            }
        
            $link = 'http://maps.google.com/maps/geo?q='.$_REQUEST['adr_1'].'+'.$_REQUEST['adr_2'].',+'.$_REQUEST['adr_zip'].',+'.$_REQUEST['adr_city'].',+'.$_REQUEST['adr_country'].'%20,%20%20&output=csv&key='.$GLOBALS['_CONFIG']['maps_key'];
            $data = @file_get_contents($link);
			
            if($data){
                $coor = explode(",",$data);
                $this->r->longitude = $coor[2];
                $this->r->latitude  = $coor[3];                
                $this->r->zoom      = (int)$_REQUEST['zoom'];
            }
            
            $this->r->link = $link;
        }
        
        function utf8_urldecode($str) {
            $str = preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\1;",urldecode($str));
            return html_entity_decode($str,null,'UTF-8');;
        }
    }